package com.gz.mylife.im;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import android.text.TextUtils;

public class IMGParams {

	//Dimens：o(原图)，b(大图) m(中图) s(小图)空默认是缩略图
	public static final String DIMENS_ORIGINAL = "o";
	public static final String DIMENS_BIG = "b";
	public static final String DIMENS_MID = "m";
	public static final String DIMENS_SMALL = "s";//小图
	
	//type：图片类型 p照片墙，u头像，t贴子
	public static final String TYPE_PHOTO_WALL = "p";
	public static final String TYPE_HEAD = "h";
	public static final String TYPE_TOPIC = "t";
	
	/**
	 * http://192.168.0.99/pic/p/b/20130623/20123239.png
	 * @author Administrator
	 */
	public static class Params{
		public String inUrl="";
		public String inDimens = "";
		public String inType = "";
		//public String inPhotoName="";
		
		@Override
		public String toString() {
			//if(!TextUtils.isEmpty(inType))
			//	inUrl =inUrl.replaceFirst("\\/[put]\\/", "/"+inType+"/");
			//if(!TextUtils.isEmpty(inDimens))
			//	inUrl =inUrl.replaceFirst("\\/s\\/", "/"+inDimens+"/");
			return inUrl;
		}
	}
	
	public static String getBigImageUrl(String urlStr){
		IMGParams.Params params = IMGParams.getParamsByUrl(urlStr);
		params.inDimens = IMGParams.DIMENS_BIG;
		return params.toString();
	}
	
	public static Params getParamsByUrl(String urlStr){
		Params params =new Params();
		if(TextUtils.isEmpty(urlStr))
			return params;
		params.inUrl = urlStr;
		Pattern p = Pattern.compile("\\/s\\/");
		Matcher matcher = p.matcher(urlStr);
		if(matcher.find()){
			//params.inUrl =urlStr;
			params.inUrl = matcher.replaceFirst("/b/");
			//params.inType  = group.substring(1, 2);
			//params.inDimens = group.substring(3, 4);
			//params.inPhotoName = group.substring(group.indexOf('/')+1, group.length());
		}
		
		Pattern p2 = Pattern.compile("(\\/s)\\d");
		Matcher matcher2 = p2.matcher(params.inUrl);
		if(matcher2.find()){
			String group = matcher2.group();
			String replace = group.replace("s", "");
			params.inUrl = matcher2.replaceFirst(replace);
		}
		
		return params;
	}
	
	public static boolean isBigPicture(String url){
		if(url.matches(".*\\/b\\/.*")){
			return true;
		} else {
			return false;
		}
	}
}
